package com.meilingcloud.biobank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meilingcloud.biobank.domain.Sample;
import com.meilingcloud.biobank.mapper.SampleMapper;
import com.meilingcloud.biobank.service.ISampleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 样本 Service业务层处理
 *
 * @author chenl
 * @date 2021-03-08
 */
@Service
public class SampleServiceImpl extends ServiceImpl<SampleMapper, Sample> implements ISampleService {

    @Override
    public List<Sample> queryList(Sample sample) {
        LambdaQueryWrapper<Sample> lqw = Wrappers.lambdaQuery();
        if (sample.getSampSourceId() != null) {
            lqw.eq(Sample::getSampSourceId, sample.getSampSourceId());
        }
        if (sample.getSampTypeId() != null) {
            lqw.eq(Sample::getSampTypeId, sample.getSampTypeId());
        }
        if (StringUtils.isNotBlank(sample.getSampCode())) {
            lqw.eq(Sample::getSampCode, sample.getSampCode());
        }
        if (sample.getSampQuantity() != null) {
            lqw.eq(Sample::getSampQuantity, sample.getSampQuantity());
        }
        if (StringUtils.isNotBlank(sample.getSampUnit())) {
            lqw.eq(Sample::getSampUnit, sample.getSampUnit());
        }
        if (sample.getSampBackupCount() != null) {
            lqw.eq(Sample::getSampBackupCount, sample.getSampBackupCount());
        }
        return this.list(lqw);
    }
}
